from common.base_page import BasePage
from appium.webdriver.common.appiumby import AppiumBy


class SellingStocks(BasePage):
    # 模拟炒股
    imitate_loc = (AppiumBy.XPATH, '//android.widget.ImageView[@bounds="[411,1491][489,1569]"]')
    # 点击卖出
    selling_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_sell')
    # 选择持仓股票
    HoldingStocks_loc = (AppiumBy.XPATH, '//android.widget.LinearLayout[@bounds="[60,328][320,416]"]')
    # 输入卖出数量
    salesQuantity_loc = (AppiumBy.ID, 'com.jhss.youguu:id/et_stock_amount')
    # 点击卖出
    clickSelling_loc = (AppiumBy.XPATH, '//android.widget.TextView[@bounds="[24,888][652,968]"]')
    # 点击确定
    determine_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_confirm')
    # 点击撤单
    cancelOrder_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_revoke')
    # 获取元素
    getEle_loc = (AppiumBy.XPATH, '//android.widget.TextView[@text="焦作万方"]')

    # 卖出操作
    def selling(self, num):
        # 模拟炒股
        self.click_ele(self.imitate_loc)
        # 点击卖出
        self.click_ele(self.selling_loc)
        # 选择持仓股票
        self.click_ele(self.HoldingStocks_loc)
        # 输入卖出数量
        self.send_keys(self.salesQuantity_loc, num)
        # 点击卖出
        self.click_ele(self.clickSelling_loc)
        # 点击确定
        self.click_ele(self.determine_loc)
        # 点击撤单
        self.click_ele(self.cancelOrder_loc)
